﻿using System;
using System.Diagnostics;
using System.Reflection;

namespace TimerUppercut.Utils
{
    public static class EventUtility
    {
        public static string AssemblyVersion
        {
            get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
        }

        /// <summary>
        /// Writes the event log
        /// </summary>
        /// <param name="entry">Information type entry</param>
        /// <param name="logName">Type of source</param>
        /// <param name="type">Type of event</param>
        /// <returns>Event status</returns>
        public static void WriteEvent(string entry, string logName, EventLogEntryType type)
        {
            #region Default values
            const string appName = "TimerUppercut";
            #endregion
            
            using (var eventLog = new EventLog())
            {
                try
                {
                    if (!(EventLog.SourceExists(appName)))
                    {
                        EventLog.CreateEventSource(appName, logName);
                    }

                    eventLog.Source = appName;
                    eventLog.WriteEntry(entry, type);
                }
                catch (Exception)
                {
                }
            }
        }
    }
}
